package com.atguigu.springcloud.controller;


import com.atguigu.springcloud.entities.entities.CommonResult;
import com.atguigu.springcloud.entities.entities.Payment;
import com.atguigu.springcloud.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderFeignController {
    //提供对外服务接口
    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping("consumer/Feign/getPaymentById/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        return paymentFeignService.getPaymentById(id);
    }

    //OpenFeign超时机制测试
    @GetMapping("consumer/Feign/timeout")
    public String PaymentFeignTimeOut() {
        // OpenFeign  底层为ribbon  客户端一般默认为1秒
        //故意让支付等待三秒  演示超时
        //演示结果  服务端可以正常运行  客户端500超时(因为OpenFeign)默认等待时间为1秒
        //在yml中设置
        return paymentFeignService.PaymentFeignTimeOut();
    }
}
